package com.matchmealpha;

import java.util.ArrayList;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

/**
 * 
 */

/**
 * @author Panda
 * 
 */
public class RecentGroup extends ActivityGroup {
	public static RecentGroup recentGroup;
	private ArrayList<View> recentHistory;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.recentHistory = new ArrayList<View>();
		recentGroup = this;

		// Start the root activity within the group and get its view
		View view = getLocalActivityManager().startActivity(
				"RecentActivity",
				new Intent(this, RecentActivity.class)
						.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
				.getDecorView();

		// Replace the view of this ActivityGroup
		replaceView(view);

	}

	public void replaceView(View v) {
		// Adds the old one to history
		recentHistory.add(v);
		// Changes this Groups View to the new View.
		setContentView(v);
	}

	public void back() {
		if (recentHistory.size() > 0) {
			recentHistory.remove(recentHistory.size() - 1);
			setContentView(recentHistory.get(recentHistory.size() - 1));
		} else {
			finish();
		}
	}

	public ArrayList<View> getHistory(){
		return recentHistory;
	}
	
	@Override
	public void onBackPressed() {
		RecentGroup.recentGroup.back();
		return;
	}
}
